package com.river.boot.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.river.boot.biz.model.entity.ProductSpecOption;
import com.river.boot.biz.model.query.ProductSpecOptionQuery;
import com.river.boot.biz.model.vo.ProductSpecOptionVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 规格选项Mapper接口
 *
 * @author JiangCheng Xiang
 * @since 2025-04-25 15:57
 */
@Mapper
public interface ProductSpecOptionMapper extends BaseMapper<ProductSpecOption> {

    /**
     * 获取规格选项分页数据
     *
     * @param page        分页对象
     * @param queryParams 查询参数
     * @return
     */
    Page<ProductSpecOptionVO> getProductSpecOptionPage(Page<ProductSpecOptionVO> page, ProductSpecOptionQuery queryParams);

    /**
     * 根据商品ID查询规格选项列表
     *
     * @param productId 商品ID
     */
    @Select("SELECT bpso.* FROM biz_product_spec_option bpso" +
            " left join river_boot.biz_product_spec bps on bpso.spec_id = bps.id" +
            " WHERE bps.product_id = #{productId}")
    List<ProductSpecOption> selectProductSpecOptionsByProductId(@Param("productId") Long productId);

    /**
     * 根据商品ID删除规格选项
     *
     * @param productId 商品ID
     */
    @Delete("DELETE FROM biz_product_spec_option WHERE spec_id IN (SELECT id FROM biz_product_spec WHERE product_id = #{productId})")
    void deleteProductSpecOptionsByProductId(@Param("productId") Long productId);
}
